home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / gsm.rexx < prev    next >
OS/2 REXX Batch file  |  2000-11-28  |  2KB  |  80 lines

  1. /* */
  2.  
  3. l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  4. prg=ProgramName("NOEXT")
  5. if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then call err "can't find" result,1
  6.  
  7. if ~RMH_ReadArgs("PREFS/A,TEL/A,TEXT/A/F") then do
  8.     call PrintFault(IoErr(),prg)
  9.     exit
  10. end
  11.  
  12. s=socket("INET","STREAM")
  13. if s<0 then call err "can't create socket"
  14.  
  15. say "Resolving host name..."
  16. sin.addraddr=resolve("www.mtn.co.za")
  17. if sin.addraddr=-1 then call err "Host not found ("hosterrorstring(hosterrorno())")",1
  18.  
  19. sin.addrport=80
  20.  
  21. say "Connecting..."
  22. if connect(s,"SIN")<0 then call err  "can't connect"
  23.  
  24. call err  "Sending request..."
  25.  
  26. arg="intlPrefix="code(parm.0.value)"&TEL="code(parm.1.value)"&Message="code(parm.2.value)
  27. fin="d0a"x
  28. post=,
  29. "POST http://www.mtn.co.za/send/sms-rich.html HTTP/1.0"fin||,
  30. "User-Agent: Amiga-AWeb/3.1"fin||,
  31. "Accept: */*;q=1"fin||,
  32. "Host: www.mtn.co.za"fin||,
  33. "Referer: http://www.mtn.co.za/sms/secure/text.html"fin||,
  34. "Content-Length:"length(arg)||fin||,
  35. "Content-Type: application/x-www-form-urlencoded"fin||fin
  36.  
  37. if send(s,post)<0 then call err "error sending"
  38. if send(s,arg)<0 then call err "error sending"
  39.  
  40. say "Receiving results..."
  41.  
  42. res=recvline(s,"BUF",256)
  43. if res>0 then do
  44.     parse var buf "HTTP/1.1 "code error"A"x
  45.     if code~=200 then call err "server error" error "("code")",1
  46. end
  47.  
  48. do while res>0
  49.     if left(buf,3)="<P>" & left(right(buf,5),4)="</P>" then do
  50.         parse var buf "<P>"buf"<"
  51.         parse var buf buf"."
  52.         leave
  53.     end
  54.     res=recvline(s,"BUF",256)
  55. end
  56. if res<0 then call err "error receiving"
  57. else do
  58.     if pos("HTML",buf)~=0 then buf="Sorry, the message was not sent"
  59.     say buf
  60. end
  61. exit
  62. /**************************************************************************/
  63. code: procedure
  64. parse arg t
  65.     res=""
  66.     do i=1 to length(t)
  67.         c=substr(t,i,1)
  68.         if (c<'0') | (c>'z') then c="%"c2x(c)
  69.         res=res||c
  70.     end
  71.     return res
  72. /**************************************************************************/
  73. err:
  74. parse arg msg,noerr
  75.     if noerr~=1 then es="("ErrorString(Errno())")"
  76.     else es=""
  77.     say prg": "msg es
  78.     exit
  79. /**************************************************************************/
  80.